package com.foo.designpattern.interpreter;

/**
 * com.foo.designpattern.interpreter
 * Created with IntelliJ IDEA.
 * Created by jiang on 2016-06-12 14:33.
 *
 * @Description 终结符表达式(Terminal Expression)角色
 * 一个Constant对象代表一个布尔常量
 */

public class Constant implements Expression {
    private boolean value;

    public Constant(boolean value) {
        this.value = value;
    }

    @Override
    public boolean interpret(Context ctx) {
        return this.value;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj != null && obj instanceof Constant) {
            return this.value == ((Constant) obj).value;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return this.toString().hashCode();
    }

    @Override
    public String toString() {
        return new Boolean(this.value).toString();
    }
}
